﻿using LowCoding.Domain.Entity;
using LowCoding.Domain.Entity.Sys;
using Microsoft.Extensions.Configuration;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LowCoding.Domain
{
    public class BaseDatatable : IBaseDatatable
    {
        /// <summary>
        /// 依赖注入
        /// </summary>
        public readonly ISqlSugarClient _client;
        public BaseDatatable(IConfiguration configuration)
        {
            _client = new SqlSugarClient(new ConnectionConfig
            {
                DbType = DbType.MySql,
                ConnectionString = configuration.GetConnectionString("TestDB")
            });
        }
        #region SqlSugar建库建表
        /// <summary>
        /// SqlSugar建库建表
        /// </summary>
        public void DataBase()
        {
            _client.DbMaintenance.CreateDatabase();
            _client.CodeFirst.SetStringDefaultLength(200).InitTables(typeof(SysName));
        }
        #endregion
    }
}
